<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <script>

    //JSON: 就是字符串
    var data = '{"name": "kevin","age": 20,"isVip": true,"city": null,"book": [{"name": "HTML", "price": 56.33}, {}],"date": "2022-09-29 10:10:10"}';

    //将JSON字符串转换为普通对象
    //反序列化
    //JSON.parse(JSON字符串);
    var mydata = JSON.parse(data);
    console.log('mydata ==> ', mydata);

    var book = mydata.book;
    console.log('book ==> ', book);

    var o = {
      a: [{x: 1, y: 2}, {x: 100, y: 200}],
      b: "黑布林",
      c: {
        book: ['html', 'css']
      }
    };

    //JSON.stringify(对象, 保留对象的字段数组)
    //将普通对象转换为JSON字符串
    //序列化
    // var oData = JSON.stringify(o);
    // var oData = JSON.stringify(o, ['a', 'c']);
    delete o.b;
    var oData = JSON.stringify(o);
    console.log('oData ==> ', oData);


    //练习: 将请求地址的查询参数转换为JSON字符串
    // https:// ==> 协议
    // www.baidu.com ==> 域名
    // /s ==> 请求路径
    // ?wd=一组数字描绘丰收里的中国&sa=fyb_n_homepage&rsv_dl=fyb_n_homepage&from=super&cl=3&tn=baidutop10&fr=top1000&rsv_idx=2&hisfilter=1 ==> 请求参数
    var url = 'https://www.baidu.com/s?wd=一组数字描绘丰收里的中国&sa=fyb_n_homepage&rsv_dl=fyb_n_homepage&from=super&cl=3&tn=baidutop10&fr=top1000&rsv_idx=2&hisfilter=1';

    //期望得到的结果
    /*
    '{"wd": "一组数字描绘丰收里的中国", "sa": "fyb_n_homepage", "rsv_dl": "fyb_n_homepage", "from": "super", "cl": 3, "tn": "baidutop10", "fr": "top1000", "rsv_idx": 2, "hisfilter": 1}'
    */



  </script>
</body>
</html>